package bist.believeinstep.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import bist.believeinstep.domain.TravelingArticle;
import bist.believeinstep.util.Constant.State;
import bist.believeinstep.util.Constant.TravelingType;

public class TravellingArticleMapper implements RowMapper<TravelingArticle> {
	public TravelingArticle mapRow(ResultSet rs, int rowNum) throws SQLException{
		TravelingArticle travelingArticle = new TravelingArticle();
		
		travelingArticle.setId(rs.getInt("id"));
		travelingArticle.setTitle(rs.getString("title"));
		travelingArticle.setContent(rs.getString("content"));
		travelingArticle.setIntroduction(rs.getString("introduction"));
		
		String type = rs.getString("type");
		travelingArticle.setType(TravelingType.create(type));
		
		travelingArticle.setAvatar(rs.getString("avatar"));
		
		String state =  rs.getString("state");
		travelingArticle.setState(State.create(state));
		
		travelingArticle.setCreated(rs.getTimestamp("created_date"));
		travelingArticle.setModified(rs.getTimestamp("modified_date"));
		travelingArticle.setCreatedBy(rs.getString("created_by"));
		travelingArticle.setModifiedBy(rs.getString("modified_by"));
		
		return travelingArticle;
	}
}
